import java.util.*;

public class Interfaces {
    public static void main5(String[] args) {
        HashMap<String,String> map = new HashMap<>();
        map.put("及时雨","宋江");
        map.put("智多星","吴用");
        System.out.println(map);
        TreeMap<String,String> map1 = new TreeMap<>();
        map1.put("及时雨","宋江");
        map1.put("智多星","吴用");
        System.out.println(map1);
    }
    public static void main4(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("及时雨","宋江");
        map.put("智多星","吴用");
        System.out.println(map);
        Set<Map.Entry<String,String>> entrySet = map.entrySet();
        for (Map.Entry<String,String> entry : entrySet){
            System.out.println("key: " + entry.getKey() + "value: " + entry.getValue());
        }
    }
    public static void main3(String[] args) {
        Map<String,String> map = new HashMap<>();
        //Map<String,String> map = new TreeMap<>();
        map.put("及时雨","宋江");
        map.put("智多星","吴用");
//        String ret = map.get("及时雨");
//        System.out.println(ret);
        String ret = map.getOrDefault("及时雨","武松");
//        String ret = map.getOrDefault("及时雨2","武松");
        System.out.println(ret);
        boolean flg = map.containsKey("及时雨");
        System.out.println(flg);
    }
    public static void main2(String[] args) {
        Collection<String> collection1 = new ArrayList<>();
        collection1.add("hello");
        collection1.add("hello1");
        System.out.println(collection1);
        Object[] objects = collection1.toArray();
        //String[] objects = (String[]) collection1.toArray();
        System.out.println(Arrays.toString(objects));
        collection1.clear();
        System.out.println(collection1);
        System.out.println(collection1.isEmpty());
    }
    public static void main1(String[] args) {
        //Collection collection = new Collection();
        Collection collection1 = new ArrayList();//(1)
        collection1.add("hello");
        collection1.add(1);
        Collection<String> collection2 = new ArrayList<>();//(2)
        //Collection<String> collection2 = new ArrayList<String>();//(3)
        collection2.add("hello");
        //collection2.add(1);
    }
}

private E[] elem = new E[5];//这个代码是错误的
//正确的方式是通过反射来创建
public MYStack(Class<E> clazz, int capacity){
    elem = (E[]) Array.newInstance(clazz, capacity);
}
